#!/bin/bash

#Created by Turk 2017-09-11
#Version 1.0
#NYX Flink STARTUP

if [ $# -lt 1 ]; then
	echo `date +"%Y-%m-%d %H:%M:%S"`  "Usage: START|STOP|RESTART"
	exit 1
fi

COMMAND=$1

WORKPATH=/root/nyx
LOGFILE=$WORKPATH/log/flinkstart.log
TOMCATPATH=/home/hadoop/tomcat6
FLINKPATH=/usr/local/flink


function startup()
{
	echo `date +"%Y-%m-%d %H:%M:%S"`  "START FLINK LOCAL" | tee -a $LOGFILE
	$FLINKPATH/bin/start-local.sh
	$FLINKPATH/bin/flink run -c com.aotain.nyx.flink.NyxFlinkStart  $WORKPATH/lib/hades-nyx-0.0.1-SNAPSHOT.jar 1>>$LOGFILE 2>>$LOGFILE
	echo 'FLINK START SUCCESS!'
}

function stop()
{
	#START Flink
	echo `date +"%Y-%m-%d %H:%M:%S"`  "STOP FLINK LOCAL" | tee -a $LOGFILE
	$FLINKPATH/bin/stop-local.sh
	echo 'FLINK STOP SUCCESS!'
}

function restart()
{
	#START Flink
	echo `date +"%Y-%m-%d %H:%M:%S"`  "STOP FLINK LOCAL" | tee -a $LOGFILE
	$FLINKPATH/bin/stop-local.sh
	echo `date +"%Y-%m-%d %H:%M:%S"`  "START FLINK LOCAL" | tee -a $LOGFILE
	$FLINKPATH/bin/start-local.sh
	$FLINKPATH/bin/flink run -c com.aotain.nyx.flink.NyxFlinkStart $WORKPATH/lib/hades-nyx-0.0.1-SNAPSHOT.jar 1>>$LOGFILE 2>>$LOGFILE
	echo 'FLINK RESTART SUCCESS!'
}


if [ ${COMMAND} = "START" ]; then
	startup;
elif [ ${COMMAND} = "STOP" ]; then
	stop;
elif [ ${COMMAND} = "RESTART" ]; then
	restart;
fi

exit 0

